<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>Nemocnicni anomalie</title>
 </head>
 <body>
<?php
require_once ("model/User.php");
require_once ("controller/CategoryController.php");
require_once ("controller/ProductController.php");
require_once ("controller/CartController.php");
require_once ("Utils/Utils.php");
require_once ("components/LoginComponent.php");

session_start();

$controller = new CategoryController();
$productController = new ProductController();
$cartController = new CartController();

$loginComp = new LoginComponent("index.php".Utils::rewriteParameters());

$pole = $controller->loadCategoryByParent(null);

for ($i = 0; $i < count($pole); $i++) {
	echo "<span><a href='index.php?cat=" . $pole[$i]->getCategoryId() . "'>" . $pole[$i]->getCategoryName() . "</a></span><br>";

	if (($cat = Utils :: requestGet('cat')) != null) {
		$pole1 = $controller->loadCategoryByParent($cat);

		if ($pole[$i]->getCategoryId() != $cat)
			continue;

		for ($j = 0; $j < count($pole1); $j++) {
			echo "<span style='padding-left:10px;'><a href='index.php?cat=" . $pole1[$j]->getCategoryParent() . "&subcat=" . $pole1[$j]->getCategoryId() . "'>" . $pole1[$j]->getCategoryName() . "</a></span><br>";

			if (($subcat = Utils :: requestGet('subcat')) != null && $cat != null) {
				$pole3 = $controller->loadCategoryByParent($subcat);

				if ($pole1[$j]->getCategoryId() != $subcat)
					continue;

				for ($k = 0; $k < count($pole3); $k++) {
					echo "<span style='padding-left:20px;'>" . $pole3[$k]->getCategoryName() . "</span><br>";
				}

			}

		}
	}
}

echo "<br><br>";

if($subcat != null){
	
	$page = Utils::requestGet('page');
	
	if(($page == null) || ($page < 0)){
		$page = 0;
	}

		$config['counter'] = 3;
		$config['rewrite'] = "index.php".Utils::rewriteParametersWithout("page");
		$config['numStyle'] = "font-family:verdana;font-size:12px;text-decoration:none;";
		$config['arrows'] = 1;
	
	$productController->createProductPager($subcat, $page, $config);
}
$user = Utils::sessionGet("LOGGED_USER");
if (!is_null($user)){
	$c = $cartController->getItemCount($user->getCartNumber());
	echo "<br><a href='cart.php'>Muj nakupni kosik($c)</a>";	
}

Utils::sessionSet("LOGGED_ADMIN","admin");

?>

 </body>
</html>
